#pragma once

#include "Cell.h"
#include<QPainter>
#include<QStyleOptionGraphicsItem>
#include<QGraphicsObject>
#include<QGraphicsScene>
#include<QRectF>


class GameField:public QGraphicsObject
{
    Q_OBJECT
public:
   GameField(int width, int height, const QString& map, QGraphicsScene *Scene, QWidget * parent = 0, Qt::WFlags flags = 0, int ItemLength = 25);

   int GetWidth()
   {
      return m_width;
   }

   int GetHeight()
   {
      return m_height;
   }

   Cell* GetCell(int x, int y)
   {
      if (x < 0 || y < 0 || x >= m_width || y >= m_height)
      {
         return 0;
      }
      return m_ptr2_cells[x][y];
   }

   void DrawAll()
   {
      for (int x = 0; x < m_width; x++)
      {
         for (int y = 0; y < m_height; y++)
         {
            m_ptr2_cells[x][y]->update();
         }
      }
   }

   void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
   QRectF boundingRect() const;

   int GetFieldWidth();
   int GetFieldHaight();
protected:
   void advance();
private:
   int itemLength;
   int m_height;
   int m_width;
   Cell *** m_ptr2_cells;
};
